#include "common.hpp"
#include "log.hpp"


int main()
{
    //Log log;
    Log log(ONE_FILE);

    //建立管道
    Inif inif;
    log(Info, "build pipe success");


    //打开管道
    int fd = open(Filename, O_RDONLY);
    if(fd < 0)
    {
        //perror("open");
        log(Fatal, "error mess: %s, error code: %d", strerror(errno), errno);
        exit(OPEN_ERR);
    }


    log(Info, "open pipe success");


    //进行通信——读端
    while(true)
    {
        char receive[SIZE] = {0};
        ssize_t n = read(fd, receive, sizeof(receive));
        if(n > 0)
        {
            std::cout << "client says: " << receive << std::endl;
        }
        else if(n == 0)
        {
            std::cout << "client quit, me too!" << std::endl;
            break;
        }
        else 
            break;
    }

    //关闭管道
    int ret = close(fd);
    if(ret == -1)
    {
        //perror("close");
        log(Error, "error mess: %s, error code: %d", strerror(errno), errno);
        exit(CLOSE_ERR);
    }

    log(Info, "close pipe success");

    //释放管道
    //调用析构

    return 0;
}